﻿namespace PerpetuumSoft.InstrumentationPDA
{
    using System;
    using System.Drawing;

    public class Bevel
    {
        private bool innerBorder;
        private bool outterBorder;
        private BevelStyle style;

        public Bevel(BevelStyle style, bool outterBorder, bool innerBorder)
        {
            this.style = style;
            this.innerBorder = innerBorder;
            this.outterBorder = outterBorder;
        }

        public void Draw(Graphics g, Rectangle r)
        {
            if (this.style != BevelStyle.None)
            {
                Point location = r.Location;
                Point point2 = new Point(r.Location.X + r.Size.Width, r.Location.Y + r.Size.Height);
                if (this.outterBorder)
                {
                    g.DrawRectangle(new Pen(Color.Black), r);
                    location.X++;
                    location.Y++;
                    point2.X--;
                    point2.Y--;
                }
                Pen pen = new Pen(SystemColors.ControlLightLight);
                Pen pen2 = new Pen(SystemColors.ControlDark);
                Pen pen3 = new Pen(Color.Black);
                Pen pen4 = new Pen(Color.Black);
                switch (this.style)
                {
                    case BevelStyle.Flat:
                        pen3 = pen2;
                        pen4 = pen2;
                        break;

                    case BevelStyle.Single:
                        pen3 = new Pen(Color.Black);
                        pen4 = new Pen(Color.Black);
                        break;

                    case BevelStyle.Double:
                        pen3 = new Pen(Color.Black);
                        pen4 = new Pen(Color.Black);
                        break;

                    case BevelStyle.Raised:
                        pen3 = pen;
                        pen4 = pen2;
                        break;

                    case BevelStyle.Lowered:
                        pen3 = pen2;
                        pen4 = pen;
                        break;

                    case BevelStyle.DoubleRaised:
                        pen3 = pen;
                        pen4 = pen2;
                        break;

                    case BevelStyle.DoubleLowered:
                        pen3 = pen2;
                        pen4 = pen;
                        break;

                    case BevelStyle.FrameRaised:
                        pen3 = pen;
                        pen4 = pen2;
                        break;

                    case BevelStyle.FrameLowered:
                        pen3 = pen2;
                        pen4 = pen;
                        break;
                }
                g.DrawLine(pen3, location.X, location.Y, location.X, point2.Y);
                g.DrawLine(pen3, location.X, location.Y, point2.X, location.Y);
                g.DrawLine(pen4, location.X, point2.Y, point2.X, point2.Y);
                g.DrawLine(pen4, point2.X, location.Y, point2.X, point2.Y);
                if (((this.style == BevelStyle.Double) || (this.style == BevelStyle.DoubleRaised)) || (((this.style == BevelStyle.DoubleLowered) || (this.style == BevelStyle.FrameLowered)) || (this.style == BevelStyle.FrameRaised)))
                {
                    if ((this.style == BevelStyle.FrameLowered) || (this.style == BevelStyle.FrameRaised))
                    {
                        Pen pen5 = pen3;
                        pen3 = pen4;
                        pen4 = pen5;
                    }
                    location.X++;
                    location.Y++;
                    point2.X--;
                    point2.Y--;
                    g.DrawLine(pen3, location.X, location.Y, location.X, point2.Y);
                    g.DrawLine(pen3, location.X, location.Y, point2.X, location.Y);
                    g.DrawLine(pen4, location.X, point2.Y, point2.X, point2.Y);
                    g.DrawLine(pen4, point2.X, location.Y, point2.X, point2.Y);
                }
                if (this.innerBorder)
                {
                    Rectangle rect = new Rectangle(location.X + 1, location.Y + 1, (point2.X - location.X) - 2, (point2.Y - location.Y) - 2);
                    g.DrawRectangle(new Pen(Color.Black), rect);
                }
            }
        }

        public int GetMargin()
        {
            int num = 0;
            if (this.style == BevelStyle.None)
            {
                num = 0;
            }
            else if (((this.style == BevelStyle.Flat) || (this.style == BevelStyle.Single)) || ((this.style == BevelStyle.Raised) || (this.style == BevelStyle.Lowered)))
            {
                num = 1;
            }
            else
            {
                num = 2;
            }
            if (this.outterBorder)
            {
                num++;
            }
            if (this.innerBorder)
            {
                num++;
            }
            return num;
        }

        public bool InnerBorder
        {
            get
            {
                return this.innerBorder;
            }
            set
            {
                this.innerBorder = value;
            }
        }

        public bool OutterBorder
        {
            get
            {
                return this.outterBorder;
            }
            set
            {
                this.outterBorder = value;
            }
        }

        public BevelStyle Style
        {
            get
            {
                return this.style;
            }
            set
            {
                this.style = value;
            }
        }
    }
}

